/**
 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

class TestClass {
  field: {{.item.name}};
  constructor() {
    this.field = {{.item.init_values | first}};
  }
}

function main(): int {
    let failCounter: int = 0;
    let testResult: int = 0;
    let classValue : ClassValue = Value.of(new TestClass()) as ClassValue;
    let actualValue : {{.item.value_name}}Value;
    let storedValue : {{.item.value_name}}Value;
    {% for init_value in item.init_values %}
      actualValue = Value.of({{.init_value}}) as {{.item.value_name}}Value;
      classValue.setFieldByName("field", actualValue);
      storedValue = classValue.getFieldByName("field") as {{.item.value_name}}Value;
      {% if item.primitive %}
      testResult = checkTestResult(actualValue.getValueData() as {{.item.name}}, storedValue.getValueData() as {{.item.name}});
      {% else %}
      testResult = checkTestResult(actualValue.getData() as {{.item.name}}, storedValue.getData() as {{.item.name}});
      {% endif %}
      printTestVerdict(testResult, "TestClass field of {{.item.name}} type");
      failCounter += testResult;
    {% endfor %}
    if (failCounter > 0) return 1
    return 0;
}

function printTestVerdict(flag: int, testName: String) {
    if (flag == 0) {
      console.println(testName + " : PASSED")
    } else {
      console.println(testName + " : FAILED")
    }
}
